package net.crazyadam

import math._

/**
 *
 * @author joseph
 * @since 6/19/12 4:00 PM
 */

class Section {
  var section=List[Point]()
  /**
   *
   * @return average radians
   */
  def averageTheta: Double = {
    var sum = 0.0
    var count = 0
    section.foreach(p => {
      if (p.valid) {
        sum += cos(p.theta)
        count += 1
      }
    })
    acos(sum / count)
  }
  def addPoint(p:Point){
    section::=p //p添加到section末尾
  }
  def length(e:Earth):Double={
     e.distance(section.last,section.head)
  }
  def merge(s:List[Point]):Section={
    section:::=s //s添加在section後面
    this
  }
  def merge(s:Section):Section=merge(s.section)

  override def toString = {
    section.mkString("|")
  }
}



